package com.ruoyi.carousel.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.carousel.domain.ShCarousel;
import com.ruoyi.carousel.service.IShCarouselService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 轮播图管理Controller
 * 
 * @author GGB
 * @date 2021-09-23
 */
@Controller
@RequestMapping("/shCarousel/carousel")
public class ShCarouselController extends BaseController
{
    private String prefix = "shCarousel/carousel";

    @Autowired
    private IShCarouselService shCarouselService;

    @RequiresPermissions("shCarousel:carousel:view")
    @GetMapping()
    public String carousel()
    {
        return prefix + "/carousel";
    }

    /**
     * 查询轮播图管理列表
     */
    @RequiresPermissions("shCarousel:carousel:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ShCarousel shCarousel)
    {
        startPage();
        List<ShCarousel> list = shCarouselService.selectShCarouselList(shCarousel);
        return getDataTable(list);
    }

    /**
     * 导出轮播图管理列表
     */
    @RequiresPermissions("shCarousel:carousel:export")
    @Log(title = "轮播图管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShCarousel shCarousel)
    {
        List<ShCarousel> list = shCarouselService.selectShCarouselList(shCarousel);
        ExcelUtil<ShCarousel> util = new ExcelUtil<ShCarousel>(ShCarousel.class);
        return util.exportExcel(list, "轮播图管理数据");
    }

    /**
     * 新增轮播图管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存轮播图管理
     */
    @RequiresPermissions("shCarousel:carousel:add")
    @Log(title = "轮播图管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ShCarousel shCarousel)
    {
        return toAjax(shCarouselService.insertShCarousel(shCarousel));
    }

    /**
     * 修改轮播图管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ShCarousel shCarousel = shCarouselService.selectShCarouselById(id);
        mmap.put("shCarousel", shCarousel);
        return prefix + "/edit";
    }

    /**
     * 修改保存轮播图管理
     */
    @RequiresPermissions("shCarousel:carousel:edit")
    @Log(title = "轮播图管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ShCarousel shCarousel)
    {
        return toAjax(shCarouselService.updateShCarousel(shCarousel));
    }

    /**
     * 删除轮播图管理
     */
    @RequiresPermissions("shCarousel:carousel:remove")
    @Log(title = "轮播图管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(shCarouselService.deleteShCarouselByIds(ids));
    }
}
